﻿#include "GUIMaterialTypeDialog.h"
#include "ui_GUIMaterialTypeDialog.h"
#include "FITK_Component/FITKRadiossData/FITKRadiossCase.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractMaterial.h"
#include "FITK_Component/FITKRadiossData/FITKMaterialPlasJohns.h"
#include "FITK_Component/FITKRadiossData/FITKMaterialPlasTab.h"
#include "FITK_Component/FITKRadiossData/FITKMaterialElastic.h"
namespace GUI
{
    GUIMaterialTypeDialog::GUIMaterialTypeDialog(QWidget* parent): QDialog(parent)
        , _ui(new Ui::GUIMaterialTypeDialog)
    {
        _ui->setupUi(this);
        setMinimumSize(0, 0); // 允许窗口任意缩小
        adjustSize(); // 根据内容调整尺寸

        _ui->comboBox_type->addItem(tr("Johnson-Cook"),0/* MaterialType::Johnson */);
        _ui->comboBox_type->addItem(tr("Elastic"),1/* Elastic */);
        _ui->comboBox_type->addItem(tr("PlasTab"),2/* PlasTab */);

        Radioss::FITKRadiossCase* caseObj = FITKAPP->getGlobalData()->
            getPhysicsData<Radioss::FITKRadiossCase>();
        if (caseObj == nullptr) return;
        auto matMgr = caseObj->getMaterialManager();
        if (!matMgr)return;
        _ui->lineEdit_name->setText(matMgr->checkName("Material-1"));
        _ui->lineEdit->setReadOnly(true);
    }

    GUIMaterialTypeDialog::~GUIMaterialTypeDialog()
    {
        if (_ui)
            delete _ui;
        _ui = nullptr;
    }

    int GUIMaterialTypeDialog::selectedMaterialType() const
    {
        return _ui->comboBox_type->currentData().toInt();
    }

    void GUIMaterialTypeDialog::on_pushButtonOK_clicked()
    {
        this->accept();
    }

    void GUIMaterialTypeDialog::on_pushButtonCancel_clicked()
    {
        this->reject();
    }

    void GUIMaterialTypeDialog::on_comboBox_type_currentIndexChanged(int index)
    {
        if (index == 0)
            _ui->lineEdit->setText(Radioss::FITKMaterialPlasJohns::GetFITKMaterialPlasJohnsRadiossKeyWord());
        else if(index == 1)
            _ui->lineEdit->setText(Radioss::FITKMaterialElastic::GetFITKMaterialElasticRadiossKeyWord());
        else
            _ui->lineEdit->setText(Radioss::FITKMaterialPlasTab::GetFITKMaterialPlasTabRadiossKeyWord());
    }
    QString GUIMaterialTypeDialog::getMaterialName()
    {
        return _ui->lineEdit_name->text();
    }
} // namespace GUI
